package com.inossem.allotin.db.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.inossem.allotin.db.greendao.convert.TransportHeadConvert;
import com.inossem.wms.vo.transport.TransportHead;

import com.inossem.allotin.db.AllotInBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "ALLOT_IN_BEAN".
*/
public class AllotInBeanDao extends AbstractDao<AllotInBean, Long> {

    public static final String TABLENAME = "ALLOT_IN_BEAN";

    /**
     * Properties of entity AllotInBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property MTransportHead = new Property(1, String.class, "mTransportHead", false, "M_TRANSPORT_HEAD");
        public final static Property CreateTime = new Property(2, java.util.Date.class, "createTime", false, "CREATE_TIME");
        public final static Property StockTransportCode = new Property(3, String.class, "stockTransportCode", false, "STOCK_TRANSPORT_CODE");
    }

    private final TransportHeadConvert mTransportHeadConverter = new TransportHeadConvert();

    public AllotInBeanDao(DaoConfig config) {
        super(config);
    }
    
    public AllotInBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"ALLOT_IN_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"M_TRANSPORT_HEAD\" TEXT," + // 1: mTransportHead
                "\"CREATE_TIME\" INTEGER," + // 2: createTime
                "\"STOCK_TRANSPORT_CODE\" TEXT);"); // 3: stockTransportCode
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"ALLOT_IN_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, AllotInBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        TransportHead mTransportHead = entity.getMTransportHead();
        if (mTransportHead != null) {
            stmt.bindString(2, mTransportHeadConverter.convertToDatabaseValue(mTransportHead));
        }
 
        java.util.Date createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(3, createTime.getTime());
        }
 
        String stockTransportCode = entity.getStockTransportCode();
        if (stockTransportCode != null) {
            stmt.bindString(4, stockTransportCode);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AllotInBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        TransportHead mTransportHead = entity.getMTransportHead();
        if (mTransportHead != null) {
            stmt.bindString(2, mTransportHeadConverter.convertToDatabaseValue(mTransportHead));
        }
 
        java.util.Date createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(3, createTime.getTime());
        }
 
        String stockTransportCode = entity.getStockTransportCode();
        if (stockTransportCode != null) {
            stmt.bindString(4, stockTransportCode);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public AllotInBean readEntity(Cursor cursor, int offset) {
        AllotInBean entity = new AllotInBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : mTransportHeadConverter.convertToEntityProperty(cursor.getString(offset + 1)), // mTransportHead
            cursor.isNull(offset + 2) ? null : new java.util.Date(cursor.getLong(offset + 2)), // createTime
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // stockTransportCode
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AllotInBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setMTransportHead(cursor.isNull(offset + 1) ? null : mTransportHeadConverter.convertToEntityProperty(cursor.getString(offset + 1)));
        entity.setCreateTime(cursor.isNull(offset + 2) ? null : new java.util.Date(cursor.getLong(offset + 2)));
        entity.setStockTransportCode(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(AllotInBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(AllotInBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(AllotInBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
